/* replication files for the article:
 
Yordanova, Nikoleta & Zhelyazkova, Asya (2024)
'Delegating legislative powers to the European Commission: 
The threat of non- compliance with tertiary legislation in the member states',
Journal of Public Policy.

Please cite this publication for any use of this data.

Last updated on 4 March 2024) */

*/

cd "C:\Users\yordanovan1\Dropbox\delegated acts paper\Paper on compliance with tertiary acts\Submission to JPP\Conditional acceptance - resubmission on ... March 2024\Data"
*cd "D:\nyordano\Dropbox\delegated acts paper\EUSA_2019\Analysis"
use "Delegating Leg Powers COM_Yordanova Zhelyazkova JPP 2024.dta", clear
set scheme s1mono

*Instakk package palette_all here: findit palette_all 	//view names of Stata colors




***********************************************
***********************************************
**********MAIN TEXT ANALYSIS*******************
*********************************************** 
***********************************************


*******************************************************************************************
****** Table 2: Cross-classified multilevel logistic regression of Transposition Delays ***
*******************************************************************************************


**** ANALYSIS OF TRANSPOSITION DELAY

** MODEL 1 ** 

 
xi: xtmelogit delay delegated dist_gov_comMedian_policy1_lo gee cee vw complexity   govt_change_bin  deadline_length i.policy          || _all:R.Member_state  || CELEXnumber: , variance 

margins, dydx(delegated)
   
est store A
_diparm lns1_1_1, f(exp(@)^2) d(2*exp(@)^2)
return list  
estadd r(est), prefix(MS)
estadd r(se), prefix(MS)
 _diparm lns2_1_1,   f(exp(@)^2) d(2*exp(@)^2)
return list
estadd r(est), prefix(Dir)  
estadd r(se), prefix(Dir)



 
set scheme s1mono	
	*## Partner Committee
	capture drop xaxis-predLw
	
	gen xaxis = .
	gen pred = .
	gen predHi = .
	gen predLw = .
	
	local a = 1
	forvalues i = 0(1)1 {
			
		replace xaxis = `i' in `a'
		
		margins, at(delegated=`i') level(95) predict(mu fixedonly) vsquish


		matrix A = r(table)
		matrix list A 
	
		
		replace pred   = A[1, 1] in `a'
		replace predLw = A[5, 1] in `a'
		replace predHi = A[6, 1] in `a'
				
		local a = `a' + 1
	}
		
	# delimit ;
	twoway (rcap predLw predHi xaxis)
		|| (scatter pred xaxis   ,        lcolor(gs9)),			 
			xlabel(0 "Implementing directive" 1 "Delegated directive",  labsize(3) nogrid)
			ylabel(, axis(1) labsize(2) nogrid)
			yscale(noline) xscale(range(-0.5 1.5) noline) 
			xtitle("")
			legend(off)
			ytitle("Predicted pobability of transposition delay", axis(1) size(3) )
			title("Average Marginal Effect of Type of Act on the Pobability of Transposition Delay",  size(3.5))
			name(delegated, replace);
	# delimit cr		 

graph display, ysize(1) xsize(1.5)
gr export Fig_Delegated.png, replace


 
 
 *** MODEL 2:

 xi: xtmelogit delay c.dist_gov_comMedian_policy1_lo##i.delegated  gee cee vw complexity   govt_change_bin  deadline_length i.policy   if dist_gov_comMedian_policy1_lo<11        || _all:R.Member_state  || CELEXnumber: , variance 


est store B
_diparm lns1_1_1, f(exp(@)^2) d(2*exp(@)^2)
return list  
estadd r(est), prefix(MS)
estadd r(se), prefix(MS)
 _diparm lns2_1_1,   f(exp(@)^2) d(2*exp(@)^2)
return list
estadd r(est), prefix(Dir)  
estadd r(se), prefix(Dir)



*### Marginal Effect Plot -- Figure 1 ###* 

set scheme s1mono	
	*## Partner Committee
	capture drop xaxis-predLw
	
	gen xaxis = .
	gen pred1 = .
	gen pred1Hi = .
	gen pred1Lw = .

	gen pred2 = .
	gen pred2Hi = .
	gen pred2Lw = .
	
		local a = 1
		forvalues i = 0(1)10 {
				
			replace xaxis = `i' in `a'
			
			margins delegated if e(sample), at(dist_gov_comMedian_policy1_lo=`i')  level(95) predict(mu fixedonly) vsquish


			matrix A = r(table)
			matrix list A 
		
			
			replace pred1   = A[1, 1] in `a'
			replace pred1Lw = A[5, 1] in `a'
			replace pred1Hi = A[6, 1] in `a'
			
			replace pred2   = A[1, 2] in `a'
			replace pred2Lw = A[5, 2] in `a'
			replace pred2Hi = A[6, 2] in `a'
			
			
			local a = `a' + 1
		}
			
		# delimit ;
		twoway (hist dist_gov_comMedian_policy1_lo if e(sample),  freq color(gs14) yaxis(2))
			|| (line pred1Lw xaxis if xaxis<11, clwidth(thin) lpattern(dash) lcolor(black))
			|| (line pred1Hi xaxi if xaxis<11, clwidth(thin) lpattern(dash) lcolor(black))
			|| (line pred1 xaxis if xaxis<11,clwidth(medium) lcolor(black))
			|| (line pred2Lw xaxis if xaxis<11, clwidth(thin) lpattern(dash) lcolor(gs9))
			|| (line pred2Hi xaxis if xaxis<11, clwidth(thin) lpattern(dash) lcolor(gs9))
			|| (line pred2 xaxis if xaxis<11, clwidth(medium)  lcolor(gs9)),			 
				xlabel(0(1)10, labsize(2) nogrid)
				ylabel(, axis(1) labsize(2) nogrid)
				ylabel(, axis(2) labsize(2) nogrid)
				yscale(noline alt) yscale(noline alt axis(2)) xscale(noline)
				legend(order(4 "Implementing directive" 7 "Delegated directive" 1 "Observations") rows(1) size(2)) 
				xtitle("Policy divergence between the Government and the Commission", size(3))
				ytitle("Predicted probability of transposition delay", axis(1) size(3) )
				ytitle("Number of observations", axis(2) size(3))
				title("Average Marginal Effect of Government-Commission Policy Divergence" "on the Probability of Transposition Delay",  size(3.5))
				name(policy_divergence, replace);
		# delimit cr		 

gr export Fig_PolicyDivergence_delay.png, replace		 
drop xaxis pred1 pred1Hi pred1Lw pred2 pred2Hi pred2Lw   
	
 
 
 
***** MODEL 3 

xi: xtmelogit delay dist_gov_comMedian_policy1_lo c.gee##i.delegated  cee vw complexity  govt_change_bin  deadline_length i.policy    if dist_gov_comMedian_policy1_lo<11        || _all:R.Member_state  || CELEXnumber: , variance 


est store C
_diparm lns1_1_1, f(exp(@)^2) d(2*exp(@)^2)
return list  
estadd r(est), prefix(MS)
estadd r(se), prefix(MS)
 _diparm lns2_1_1,   f(exp(@)^2) d(2*exp(@)^2)
return list
estadd r(est), prefix(Dir)  
estadd r(se), prefix(Dir)

		
*### Marginal Effect Plot -- Figure 2 ###* 


set scheme s1mono	
	*## Partner Committee

	gen xaxis = .
	gen pred1 = .
	gen pred1Hi = .
	gen pred1Lw = .

	gen pred2 = .
	gen pred2Hi = .
	gen pred2Lw = .
	
	local a = 1
	forvalues i = -.4(0.4)2.5 {
			
		replace xaxis = `i' in `a'
		
		margins delegated if e(sample), at(gee=`i')  level(95) predict(mu fixedonly) vsquish


		matrix A = r(table)
		matrix list A 
	
		
		replace pred1   = A[1, 1] in `a'
		replace pred1Lw = A[5, 1] in `a'
		replace pred1Hi = A[6, 1] in `a'
		
		replace pred2   = A[1, 2] in `a'
		replace pred2Lw = A[5, 2] in `a'
		replace pred2Hi = A[6, 2] in `a'
		
		
		local a = `a' + 1
	}
		
	# delimit ;
	twoway (hist gee if e(sample),  freq color(gs14) yaxis(2))
		|| (line pred1Lw xaxis, clwidth(thin) lpattern(dash) lcolor(black))
		|| (line pred1Hi xaxi, clwidth(thin) lpattern(dash) lcolor(black))
		|| (line pred1 xaxis, clwidth(medium) lcolor(black))
		|| (line pred2Lw xaxis, clwidth(thin) lpattern(dash) lcolor(gs9))
		|| (line pred2Hi xaxis, clwidth(thin) lpattern(dash) lcolor(gs9))
		|| (line pred2 xaxis, clwidth(medium) lcolor(gs9)),			 
			xlabel(-.4(0.4)2.5, labsize(2) nogrid)
			ylabel(, axis(1) labsize(2) nogrid)
			ylabel(, axis(2) labsize(2) nogrid)
			yscale(noline alt) yscale(noline alt axis(2)) xscale(noline)
			legend(order(4 "Implementing directive" 7 "Delegated directive" 1 "Observations") rows(1) size(2)) 
			xtitle("Government effectiveness", size(3))
			ytitle("Predicted probability of transposition delay", axis(1) size(3) )
			ytitle("Number of observations", axis(2) size(3))
			title("Average Marginal Effect of Government Effectiveness on the" "Probability of Transposition Delay",  size(3.5))
			name(gov_effectiveness, replace);
	# delimit cr		 
			 
gr export Fig_GovEffectiveness_delay.png, replace
drop xaxis pred1 pred1Hi pred1Lw pred2 pred2Hi pred2Lw



esttab A B C using "delay_models.rtf", se  star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label replace  ///
		stats(MSest MSse Direst Dirse N ll, fmt(3 3 3 3 0 1) labels("Var (member state level)" "" "Var (directive level)" "" "Observations"  `"LR chi2"' )) 	
	



	
	
	

***********************************
***********************************
********** APPENDIX ***************
***********************************
***********************************

******************************************************************************************
****** Table 3: Cross-classified multilevel logistic regression of Infringement Cases  ***
******************************************************************************************


**** ANALYSIS OF LETTERS OF FORMAL NOTICE

*** MODEL 1 
xi: xtmelogit let delegated dist_gov_comMedian_policy1_lo c.gee   cee vw complexity  govt_change_bin  deadline_length i.policy          || _all:R.Member_state  || CELEXnumber: , variance 		
est store A1

_diparm lns1_1_1, f(exp(@)^2) d(2*exp(@)^2)
return list  
estadd r(est), prefix(MS)
estadd r(se), prefix(MS)
 _diparm lns2_1_1,   f(exp(@)^2) d(2*exp(@)^2)
return list
estadd r(est), prefix(Dir)  
estadd r(se), prefix(Dir) 
	


*** MODEL 2 
		
xi: xtmelogit let c.dist_gov_comMedian_policy1_lo##i.delegated  gee cee vw complexity   govt_change_bin  deadline_length i.policy   if dist_gov_comMedian_policy1_lo<11        || _all:R.Member_state  || CELEXnumber: , variance 
est store A2

_diparm lns1_1_1, f(exp(@)^2) d(2*exp(@)^2)
return list  
estadd r(est), prefix(MS)
estadd r(se), prefix(MS)
 _diparm lns2_1_1,   f(exp(@)^2) d(2*exp(@)^2)
return list
estadd r(est), prefix(Dir)  
estadd r(se), prefix(Dir)

	
	
*** MODEL 3 
	
xi: xtmelogit let dist_gov_comMedian_policy1_lo c.gee##i.delegated  cee vw complexity  govt_change_bin  deadline_length i.policy    if dist_gov_comMedian_policy1_lo<11        || _all:R.Member_state  || CELEXnumber: , variance 
est store A3

_diparm lns1_1_1, f(exp(@)^2) d(2*exp(@)^2)
return list  
estadd r(est), prefix(MS)
estadd r(se), prefix(MS)
 _diparm lns2_1_1,   f(exp(@)^2) d(2*exp(@)^2)
return list
estadd r(est), prefix(Dir)  
estadd r(se), prefix(Dir)

esttab A1 A2 A3 using "let_models.rtf", se  star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label replace  ///
		stats(MSest MSse Direst Dirse N ll, fmt(3 3 3 3 0 1) labels("Var (member state level)" "" "Var (directive level)" "" "Observations"  `"LR chi2"' )) 	
	

	
	
***************************************************************************************************
****** Table 4: Robustness checks: Including a proxy for non-controversial directive **************
****************(Models 1 and 3) and rare event analysis of reasoned opinions (Models 2 and 3)  ***
***************************************************************************************************	



*Model 1 with includes measures for both  MEASURES FOR TECHNICALITY OF A DIRECTIVE: n_words_titles deadline_length
xi: xtmelogit delay delegated dist_gov_comMedian_policy1_lo gee  cee vw complexity   govt_change_bin n_words_titles deadline_length i.policy          || _all:R.Member_state  || CELEXnumber: , variance 
est store B1

_diparm lns1_1_1, f(exp(@)^2) d(2*exp(@)^2)
return list  
estadd r(est), prefix(MS)
estadd r(se), prefix(MS)
 _diparm lns2_1_1,   f(exp(@)^2) d(2*exp(@)^2)
return list
estadd r(est), prefix(Dir)  
estadd r(se), prefix(Dir) 
		
margins, at(delegated=(0 1))  predict(mu fixedonly) vsquish
marginsplot, recast(bar) recastci(rcap)xlabel(0 "Implementing directive" 1 "Delegated directive") xtitle("") ytitle("Pr (Delayed transposition)") ///
   graphregion(margin(vsmall) color(white)) title("Average Marginal Effects with 95% CIs") legend(order(1 "Implementing" 2 "Delegated")) scheme(plotplain)

   
*Model 2 with rare event analysis of Reasons Opinions 
* the workpackage relogit needs to be installed first before running the model

findit relogit
net install relogit.pkg
xi: relogit ro delegated  dist_gov_comMedian_policy1_lo gee  cee vw complexity  govt_change_bin  deadline_length i.policy, cluster(CELEXnumber)
est store B2


*Model 3 with rare event analysis of Reasons Opinions  and measure for tehnicaloty of a directive (N of words)
xi: relogit ro delegated  dist_gov_comMedian_policy1_lo gee  cee vw complexity  govt_change_bin  n_words_titles deadline_length i.policy, cluster(CELEXnumber)
est store B3
 
esttab B1 B2 B3 using "robustness_models.rtf", se  star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label replace  ///
		stats(MSest MSse Direst Dirse N ll, fmt(3 3 3 3 0 1) labels("Var (member state level)" "" "Var (directive level)" "" "Observations"  `"LR chi2"' )) 
		
		
 
 
 
*************************************************************************************************************
****** Table 5: Robustness checks: Logistic regression of transposition delays with country fixed effects  **
***************************************************************************************************	*********


** Fixed effects model -- Appendix Table 5, Model 1
xi: logit delay delegated dist_gov_comMedian_policy1_lo gee cee vw complexity   govt_change_bin  i.policy  i.Member_state   if dist_gov_comMedian_policy1_lo<11     , cluster(CELEXnumber)
est store a3

	
***Fixed effects model -- Appendix Table 5, Model 2
xi: logit delay c.dist_gov_comMedian_policy1_lo##i.delegated  gee cee vw complexity   govt_change_bin deadline_length i.policy i.Member_state  if dist_gov_comMedian_policy1_lo<11, cluster(CELEXnumber)
est store b3
 
***Fixed effects model -- Appendix Table 5, Model 3
xi: logit delay dist_gov_comMedian_policy1_lo c.gee##i.delegated  cee vw complexity  govt_change_bin deadline_length i.policy i.Member_state   if dist_gov_comMedian_policy1_lo<11, cluster(CELEXnumber)
est store c3


esttab a3 b3 c3 using "delay_models_fixed.rtf", se  star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label replace  ///
		stats(MSest MSse Direst Dirse N ll, fmt(3 3 3 3 0 1) labels("Var (member state level)" "" "Var (directive level)" "" "Observations"  `"LR chi2"' )) 		
	


		*** END OF REPLICATION FILE ***


